import request from '@/api/request.js'
//获取文件列表
export function getFileList(folderKey='') {
  return request({
    url: `/adoc/file/auth`,
    method: 'get',
    params:{
      currentPage:1,
      folderKey,
      pageSize:9999
    }
  })
}

// 上传文件
export function uploadFile(data) {
  const postData = new FormData()
  for (const key in data) {
      postData.append(key, data[key])
  }
  return request({
    url: `/adoc/file/upload`,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data: postData
  })
}

// 获取文件类型
export function getFileType() {
  return request({
    url: `/adoc/file/type`,
    method: 'get'
  })
}

// 新增文件夹
export function postFloder (data) {
  return request({
    url: `/adoc/file/folder`,
    method: 'post',
    data
  })
}


// 删除文件
export function romoveFile (params) {
  return request({
    url: `/adoc/file`,
    method: 'delete',
    params,
    paramsSerializer:{
      serialize:function(params){
        const keys = params.filePrimaryKey.map(item=>`filePrimaryKey=${item}`).join('&')
        return `${keys}`
      }
    }
  })
}


// 下载文件
export function fileAuthVerify (params) {
  return request({
    url: `/adoc/file/auth/verify`,
    method: 'get',
    params,
    responseType: 'blob'
  })
}


// 获取文件授权对象
export function getfliesAuthobject (fileKey) {
  console.log(fileKey)
  return request({
    url: `/adoc/file/auth/object`,
    method: 'get',
    params:{
      currentPage:1,
      fileKey,
      pageSize:9999
    }
  })
}
//添加文件授权
export function addFileAuth (data) {
  return request({
    url: `/adoc/file/auth`,
    method: 'post',
    data
  })
}
//删除文件授权
export function removeFileAuth (params) {
  return request({
    url: `/adoc/file/auth`,
    method: 'delete',
    params,
    paramsSerializer:{
      serialize:function(params){
        const keys = params.authKeys.map(item=>`authKeys=${item}`).join('&')
        return `${keys}&fileKey=${params.fileKey}`
      }
    }
  })
}
// 获取用户组织
export function getOrganizationUser () {
  return request({
    url: `/system/organization/user`,
    method: 'get'
  })
}





